<template>
  <div>
    <input type="text" :value="value" style="display: none" />
    <el-select
      v-model="selected"
      :class="css"
      :clearable="clearable"
      :size="size"
      :placeholder="placeholder"
      @change="handleItemChange"
    >
      <el-option
        v-for="item in cateList"
        :key="item.deptId"
        :label="item.deptName"
        :value="item.deptId"
      ></el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    value: {
      type: String,
      default: '',
    },
    size: {
      type: String,
      default: '',
    },
    placeholder: {
      type: String,
      default: '选择部门',
    },
    clearable: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      selected: null,
      // cateList: [],
      autoChange: true,
    }
  },
  computed: {
    cateList() {
      return this.$store.getters.deptData
    },
    css() {
      return (this.$attrs && this.$attrs.class) || 'w-100'
    },
  },
  watch: {
    value(val) {
      this.selected = val
    },
  },
  created() {
    this.$store.dispatch('getDeptData')
    this.selected = this.value
  },
  mounted() {
    // this.getData()
  },
  methods: {
    handleItemChange(val = '') {
      this.$emit('input', val)
      this.$emit('change', val)
    },
    // getData() {
    //   this.$http.get('/auth/org/dept/?deptLevel=0&clientId=&deptName=').then(res => {
    //     this.cateList = res.data
    //   }).finally(() => {
    //     this.autoChange = false
    //   })
    // }
  },
}
</script>

<style scoped></style>
